package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.SystemMapper;
import com.example.servicea.entity.SystemEntity;
import com.example.servicea.service.SystemService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @Author generator.
 * @Date: 2017/10/26 10:58
 */
@Service("systemServiceImpl")
public class SystemServiceImpl implements SystemService {
	@Autowired
	private SystemMapper systemMapper;

    @Override
    public boolean insert(SystemEntity obj){
        return SqlHelper.retBool(systemMapper.insert(obj));
    }
    @Override
    public List<SystemEntity> selectList(SystemEntity system){
        EntityWrapper<SystemEntity> query = new EntityWrapper<SystemEntity>();
		return systemMapper.selectList(query);
	}

    @Override
    public Page selectPage(SystemEntity system, String page, String limit){
        EntityWrapper<SystemEntity> query = new EntityWrapper<SystemEntity>();
        if(StringUtils.isNotBlank(system.name)){
            query.like("name",system.name);
        }
        List<SystemEntity> list = systemMapper.selectPage(
                new Page<SystemEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = systemMapper.selectCount(query);
        Page SystemEntityPage = new Page();
        return SystemEntityPage;
	}
    @Override
    public int selectCount(SystemEntity system){
        EntityWrapper<SystemEntity> query = new EntityWrapper<SystemEntity>();
        return systemMapper.selectCount(query);
	}

    @Override
    public SystemEntity selectOne(SystemEntity system){
        return systemMapper.selectOne(new SystemEntity());
	}

    @Override
    public SystemEntity selectById(String id){
        return systemMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(SystemEntity system){
        return SqlHelper.retBool(systemMapper.updateById(system));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(systemMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(systemMapper.deleteBatchIds(list));
	}
	
}
